package com.partsoft.dits.ldap;

/**
 * LDAP连接类型
 */
public enum LdapConntectType {

	normal("ldap://", "不加密连接", 0),

	ssl("ldaps://", "SSL安全连接", 1),

	tls("ldapts://", "TLS安全连接", 2);

	private String title;

	private int code;

	private String connectPrefix;

	private LdapConntectType(String connectPrefix, String title, int code) {
		this.connectPrefix = connectPrefix;
		this.title = title;
		this.code = code;
	}

	public String getTitle() {
		return title;
	}

	public int getCode() {
		return code;
	}

	public String getConnectPrefix() {
		return connectPrefix;
	}

	public static LdapConntectType fromCode(int code) {
		for (LdapConntectType type : LdapConntectType.values()) {
			if (type.code == code)
				return type;
		}
		return null;
	}

	public static LdapConntectType fromName(String name) {
		for (LdapConntectType type : LdapConntectType.values()) {
			if (type.name().equals(name))
				return type;
		}
		return null;
	}

}
